// components/search/search.js
const {
    get_searchKey
} = require("../../utils/ajax")

Component({
    properties: {

    },
    data: {
        searchKeys: [],
        searchKey: ""
    },

    /**
     * 组件的方法列表
     */
    methods: {
        myInput(e) {
            this.setData({
                searchKey:e.detail.value
            }, () => {
                get_searchKey({key: this.data.searchKey}).then(res => {
                    this.setData({
                        searchKeys: res.data.map(item => item.split(/\n/)[0].split("=")[1])
                    })
                })
            })
        },
        search(e) {
            var pages = getCurrentPages();
            var thisPage = pages[pages.length - 1]
            var path = thisPage.route
            let key = e.currentTarget.dataset.key || this.data.searchKey
            if (path == "pages/searchMusic/searchMusic") {
                wx.redirectTo({
                    url: '../../pages/searchMusic/searchMusic?key' + key,
                })
            } else {
                wx.navigateTo({
                    url: '../../pages/searchMusic/searchMusic?key=' + key,
                })
            }
            this.setData({
                searchKey: ""
            })
        }
    }
})